﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Crossroad.Utils.Extensions;
using SqlSugar;

namespace Crossroad.System.User.Model
{
    ///<summary>
    ///用户信息
    ///</summary>
    [SugarTable("user_info")]
    public partial class UserInfo : ModelContext
    {
        public UserInfo()
        {
            LoadDefVal();
        }

        public UserInfo(bool loadDef)
        {
            if (loadDef)
                LoadDefVal();
        }

        private void LoadDefVal()
        {
            this.creatorId = Convert.ToInt32("0");
            this.createTime = Convert.ToInt32("0");
        }

        /// <summary>
        /// Desc:创建人
        /// Default:0
        /// Nullable:True
        /// </summary>           
        [SugarColumn(ColumnName = "creator_id")]
        public int? creatorId { get; set; }

        /// <summary>
        /// Desc:电子邮箱
        /// Default:
        /// Nullable:True
        /// </summary>           
        public string email { get; set; }

        /// <summary>
        /// Desc:id
        /// Default:
        /// Nullable:False
        /// </summary>           
        [SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
        public int id { get; set; }

        /// <summary>
        /// Desc:登录名
        /// Default:
        /// Nullable:True
        /// </summary>           
        public string username { get; set; }

        /// <summary>
        /// Desc:登陆密码
        /// Default:
        /// Nullable:True
        /// </summary>           
        public string password { get; set; }

        /// <summary>
        /// Desc:手机号
        /// Default:
        /// Nullable:True
        /// </summary>           
        public string phone { get; set; }

        /// <summary>
        /// 微信openid
        /// </summary>
        [SugarColumn(ColumnName = "wechat_open_id")]
        public string wechatOpenId { set; get; }

        /// <summary>
        /// Desc:昵称
        /// Default:
        /// Nullable:True
        /// </summary>           
        [SugarColumn(ColumnName = "nick_name")]
        public string nickName { get; set; }

        /// <summary>
        /// Desc:头像
        /// Default:
        /// Nullable:True
        /// </summary>           
        public string avatar { get; set; }

        /// <summary>
        /// Desc:创建时间
        /// Default:0
        /// Nullable:True
        /// </summary>           
        [SugarColumn(ColumnName = "create_time")]
        public int? createTime { get; set; }

        /// <summary>
        /// Desc:唯一值
        /// Default:
        /// Nullable:False
        /// </summary>           
        [SugarColumn(ColumnName = "unique_key")]
        public string uniqueKey { get; set; }

        #region 扩展属性

        /// <summary>
        /// 操作权限
        /// </summary>
        [SugarColumn(IsIgnore = true)]
        public List<string> permissions { get; set; } = new List<string>();

        private string _createTimeText;
        /// <summary>
        /// 创建时间
        /// </summary>
        [SugarColumn(IsIgnore = true)]
        public string createTimeText
        {
            set { _createTimeText = value; }
            get
            {
                if (_createTimeText.IsNullOrEmpty() && createTime.Contains())
                    return _createTimeText = createTime.Value.ToDateTimeStr();

                return _createTimeText;
            }
        }

        /// <summary>
        /// 创建人
        /// </summary>
        [SugarColumn(IsIgnore = true)]
        public string creatorName { set; get; } = string.Empty;

        /// <summary>
        /// 角色id
        /// </summary>
        [SugarColumn(IsIgnore = true)]
        public int? roleId { get; set; }

        /// <summary>
        /// 角色名
        /// </summary>
        [SugarColumn(IsIgnore = true)]
        public string roleName { get; set; }

        /// <summary>
        /// 组织架构id
        /// </summary>
        [SugarColumn(IsIgnore = true)]
        public int? organizationId { get; set; }

        [SugarColumn(IsIgnore = true)]
        public int? companyId { get; set; }
        /// <summary>
        /// 用人单位
        /// </summary>
        [SugarColumn(IsIgnore = true)]
        public string companyName { get; set; }

        [SugarColumn(IsIgnore = true)]
        public int? deptId { get; set; }
        /// <summary>
        /// 部门名称
        /// </summary>
        [SugarColumn(IsIgnore = true)]
        public string deptName { get; set; }

        #endregion
    }
}
